import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'

Vue.use(Router)
let router = new Router({
  mode: 'history',
  base: '/xwkx-web',
  routes: [
    // {
    //   path: '/',
    //   name: 'HelloWorld',
    //   component: resolve => { require(['@/components/HelloWorld'], resolve); }
    // },
    {
      path: '/',
      name: '目录',
      hidden:true,
      component: resolve => {
        require(['@/components/Catalog'], resolve);
      }
    },
    {
      path: '/common',
      name: '通用',
      //如果有层级，就必须包含以后含有router-view标签的=主页
      component: resolve => {
        require(['@/components/common/Index.vue'], resolve);
      },
      children: [
        {
          //并且子节点不要加/
          path: 'login',
          name: "登陆",
          meta: {
            title: '登陆'
          },
          component: resolve => {
            require(['@/components/common/Login.vue'], resolve);
          }
        },{
          //并且子节点不要加/
          path: 'loginNoWechat',
          name: "登陆1",
          meta: {
            title: '登陆1'
          },
          component: resolve => {
            require(['@/components/common/LoginNoWechat.vue'], resolve);
          }
        },
        {
          //并且子节点不要加/
          path: 'bindPhone',
          name: "绑定手机",
          hidden:true,
          meta: {
            title: '绑定手机'
          },
          component: resolve => {
            require(['@/components/common/BindIng.vue'], resolve);
          }
        },
        {
          //并且子节点不要加/
          path: 'bindEd',
          name: "绑定结果",
          hidden:true,
          meta: {
            title: '绑定结果'
          },
          component: resolve => {
            require(['@/components/common/BindSuccess.vue'], resolve);
          }
        },
        {
          path: 'info',
          name: "用户详情",
          meta: {
            title: '用户详情'
          },
          component: resolve => {
            require(['@/components/common/Info.vue'], resolve);
          }
        },
        {
          path: 'todo',
          name: "待开发",
          hidden:true,
          meta: {
            title: '待开发'
          },
          component: resolve => {
            require(['@/components/common/Todo.vue'], resolve);
          }
        }
      ]
    },
    {
      path: '/pay',
      name: '支付',
      hidden:true,
      component: resolve => {
        require(['@/components/user/Index.vue'], resolve);
      },
      children: [
        {
          path: 'preview/',
          name: "收费项",
          component: resolve => {
            require(['@/components/user/OrderPay.vue'], resolve);
          }
        }]
    },
    {
      path: '/attend',
      name: '打卡',
      //如果有层级，就必须包含以后含有router-view标签的=主页
      component: resolve => {
        require(['@/components/attend/Index.vue'], resolve);
      },
      children: [
        {
          path: 'execution',
          name: "打卡",
          meta: {
            title: '打卡'
          },
          hidden:true,
          component: resolve => {
            require(['@/components/attend/Execution.vue'], resolve);
          }
        }, {
          path: 'map',
          name: "地图打卡",
          meta: {
            title: '打卡'
          },
          component: resolve => {
            require(['@/components/attend/MapLocation.vue'], resolve);
          }
        },
        {
          //并且子节点不要加/
          path: 'list',
          name: "打卡记录",
          component: resolve => {
            require(['@/components/attend/list.vue'], resolve);
          }
        }
      ]
    },
    {
      path: '/user',
      name: '用户',
      //如果有层级，就必须包含以后含有router-view标签的=主页
      component: resolve => {
        require(['@/components/user/Index.vue'], resolve);
      },
      children: [
        {
          path: 'repairService',
          name: '提交工单',
          component: resolve => {
            require(['@/components/user/RepairService.vue'], resolve);
          }
        },
        {
          path: 'repairSuccess',
          name: '提交成功',
          hidden:true,
          component: resolve => {
            require(['@/components/user/RepairSuccess.vue'], resolve);
          }
        },
        {
          path: 'myOrders',
          name: '我的工单',
          component: resolve => {
            require(['@/components/user/MyOrders.vue'], resolve);
          }
        },
        {
          path: 'orderConfirm',
          name: '确认金额',
          hidden:true,
          component: resolve => {
            require(['@/components/user/OrderConfirm.vue'], resolve);
          }
        },
        {
          path: 'orderPay',
          name: '费用清单',
          hidden:true,
          component: resolve => {
            require(['@/components/user/OrderPay.vue'], resolve);
          }
        },
        {
          path: 'orderAppraise',
          name: '评价工单',
          hidden:true,
          component: resolve => {
            require(['@/components/user/OrderAppraise.vue'], resolve);
          }
        },
        {
          path: 'orderAppraiseHome',
          name: '服务评价',
          hidden:true,
          component: resolve => {
            require(['@/components/user/OrderAppraiseHome.vue'], resolve);
          }
        },
        {
          path: 'payMoney',
          name: '支付',
          hidden:true,
          component: resolve => {
            require(['@/components/user/PayMoney.vue'], resolve);
          }
        },
      ]
    },
    {
      path: '/engineer',
      name: '工程师',
      //如果有层级，就必须包含以后含有router-view标签的=主页
      component: resolve => {
        require(['@/components/engineer/Index.vue'], resolve);
      },
      children: [
        {
          path: 'login',
          name: '登陆',
          component: resolve => {
            require(['@/components/engineer/Login.vue'], resolve);
          }
        },
        {
          path: 'enApplyInOrder',
          name: '工单申请',
          component: resolve => {
            require(['@/components/engineer/EnApplyInOrder.vue'], resolve);
          }
        },
        {
          path: 'enApplyOutOrder',
          name: '工单申请',
          component: resolve => {
            require(['@/components/engineer/EnApplyOutOrder.vue'], resolve);
          }
        },
        {
          path: 'enMyOrders',
          name: '我的工单',
          component: resolve => {
            require(['@/components/engineer/EnMyOrders.vue'], resolve);
          }
        },
        {
          path: 'enReceiveOrder',
          name: '接单',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnReceiveOrder.vue'], resolve);
          }
        },
        {
          path: 'enWorkingOrder',
          name: '处理工单',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnWorkingOrder.vue'], resolve);
          }
        },
        {
          path: 'enWorkingInOrder',
          name: '处理工单',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnWorkingInOrder.vue'], resolve);
          }
        },
        {
          path: 'enWorkedInOrder',
          name: '已完成工单',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnWorkedInOrder.vue'], resolve);
          }
        },
        {
          path: 'enMyLocus',
          name: '我的行程',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnMyLocus.vue'], resolve);
          }
        },
        {
          path: 'enWorkingCatalog',
          name: '执行维修',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnWorkingCatalog.vue'], resolve);
          }
        },
        {
          path: 'enAddTollService',
          name: '添加收费项目',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnAddTollService.vue'], resolve);
          }
        },
        {
          path: 'enWorkingService',
          name: '处理过程之工程师上传处理证明',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnWorkingService.vue'], resolve);
          }
        },
        {
          path: 'enWorkingServiceStandard',
          name: '处理服务项目标准',
          hidden:true,
          component: resolve => {
            require(['@/components/engineer/EnWorkingServiceStandard.vue'], resolve);
          }
        },
        {
          path: 'enMySpareCenter',
          // hidden:true,
          name: '备件中心',
          component: resolve => {
            require(['@/components/engineer/EnMySpareCenter.vue'], resolve);
          }
        },
      ]
    },
    {
      path: '/inventory',
      name: '备品备件',
      //如果有层级，就必须包含以后含有router-view标签的=主页
      component: resolve => {
        require(['@/components/inventory/Index.vue'], resolve);
      },
      children: [
        {
          path: 'inventoryHome',
          name: '备品中心',
          component: resolve => {
            require(['@/components/inventory/inventoryHome.vue'], resolve);
          }
        },
        {
          path: 'applyInventory',
          name: '备品申请',
          hidden:true,
          component: resolve => {
            require(['@/components/inventory/applyInventory.vue'], resolve);
          }
        },
        {
          path: 'addSpare',
          name: '好件申请',
          hidden:true,
          component: resolve => {
            require(['@/components/inventory/addSpare.vue'], resolve);
          }
        },
        {
          path: 'backSpare',
          name: '坏件退回',
          hidden:true,
          component: resolve => {
            require(['@/components/inventory/backSpare.vue'], resolve);
          }
        },
        {
          path: 'spareListInfo',
          name: '坏件退回',
          hidden:true,
          component: resolve => {
            require(['@/components/inventory/spareListInfo.vue'], resolve);
          }
        },
        {
          path: 'spareStock',
          name: '备品库存',
          component: resolve => {
            require(['@/components/inventory/spareStock.vue'], resolve);
          }
        },
      ]
    },
    {
      path: '/management',
      name: '后台管理',
      //如果有层级，就必须包含以后含有router-view标签的=主页
      component: resolve => {
        require(['@/components/management/Index.vue'], resolve);
      },
      children: [
        {
          path: 'manOrderHome',
          name: '工单中心',
          component: resolve => {
            require(['@/components/management/ManOrderHome.vue'], resolve);
          }
        },
        {
          path: 'manRequestHandle',
          name: '维修请求处理',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManRequestHandle.vue'], resolve);
          }
        },
        {
          path: 'manCreatedOrder',
          name: '创建工单',
          hidden:true,
          component: resolve => {
            require(['@/components/management/ManCreatedOrder.vue'], resolve);
          }
        },
        {
          path: 'manCreatedInOrder',
          name: '创建工单',
          hidden:true,
          component: resolve => {
            require(['@/components/management/ManCreatedInOrder.vue'], resolve);
          }
        },
        {
          path: 'manDistributeOrder',
          name: '指派工单',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManDistributeOrder.vue'], resolve);
          }
        },
        {
          path: 'manQualityHome',
          name: '质检项目列表',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManQualityHome.vue'], resolve);
          }
        },
        {
          path: 'manQualityServiceItem',
          name: '质检项目',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManQualityServiceItem.vue'], resolve);
          }
        },
        {
          path: 'manEvaluateInOrder',
          name: '任务评价',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManEvaluateInOrder.vue'], resolve);
          }
        },
        {
          path: 'manCloseInOrder',
          name: '关闭工单',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManCloseInOrder.vue'], resolve);
          }
        },
        {
          path: 'manCloseOrder',
          name: '关闭工单',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManCloseOrder.vue'], resolve);
          }
        },
        {
          path: 'manOrderOutInfo',
          name: '工单详情',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManOrderOutInfo.vue'], resolve);
          }
        },
        {
          path: 'manOrderInInfo',
          name: '工单详情',
          hidden: true,
          component: resolve => {
            require(['@/components/management/ManOrderInInfo.vue'], resolve);
          }
        },
      ]
    }, {
      path: '/expense',
      name: '报销',
      //如果有层级，就必须包含以后含有router-view标签的=主页
      component: resolve => {
        require(['@/components/expense/Index.vue'], resolve);
      },
      children: [
        {
          path: 'expenseList',
          name: '报销',
          component: resolve => {
            require(['@/components/expense/expenseList.vue'], resolve);
          }
        },
        {
          path: 'createExpenseForm',
          name: '报销单',
          hidden:true,
          component: resolve => {
            require(['@/components/expense/createExpenseForm.vue'], resolve);
          }
        },
        {
          path: 'approvalList',
          name: '审核',
          component: resolve => {
            require(['@/components/expense/approvalList.vue'], resolve);
          }
        },
        {
          path: 'approvalListSearch',
          name: '审核搜索',
          hidden:true,
          component: resolve => {
            require(['@/components/expense/approvalListSearch.vue'], resolve);
          }
        },
        {
          path: 'CostFirstTrial',
          name: '初审',
          hidden:true,
          component: resolve => {
            require(['@/components/expense/CostFirstTrial.vue'], resolve);
          }
        },
        {
          path: 'CostSecondTrial',
          name: '复审',
          hidden:true,
          component: resolve => {
            require(['@/components/expense/CostSecondTrial.vue'], resolve);
          }
        }, {
          path: 'createApplyForm',
          name: '申请单',
          hidden:true,
          component: resolve => {
            require(['@/components/expense/createApplyForm.vue'], resolve);
          }
        }, {
          path: 'requestList',
          name: '申请',
          component: resolve => {
            require(['@/components/expense/requestList.vue'], resolve);
          }
        }, {
          path: 'CostApplyTrial',
          name: '申请单审核',
          hidden:true,
          component: resolve => {
            require(['@/components/expense/CostApplyTrial.vue'], resolve);
          }
        }
      ]
    },
    // {
    //   path: '/personal',
    //   name: '个人中心',
    //   component: resolve => {
    //     require(['@/components/personal/index.vue'], resolve);
    //   },
    // },
    //404应该放在最后一个
    {
      path: '/*',
      name: 'error-404',
      hidden:true,
      meta: {
        title: '404-页面不存在'
      },
      component: resolve => {
        require(['@/components/error-page/404.vue'], resolve);
      }
    }
  ]
})

router.beforeEach(function (to, from, next) {
  store.commit('updateLoadingStatus', {isLoading: true})
  if (to.meta.title) {
    document.title = to.meta.title;
  } else if (to.name) {
    document.title = to.name;
  }
  next()
})

router.afterEach(function (to) {
  store.commit('updateLoadingStatus', {isLoading: false})
})


export default router
